package com.example.classmanageapp;

import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.classmanageapp.sqlite.MyDatabaseHelper;
import com.example.classmanageapp.utils.SysUtils;

public class MessageEditActivity extends Activity {

    private TextView tv_cacel;
    private TextView tv_finish;
    private EditText et_nickname;
    private EditText et_signature;
    private MyDatabaseHelper dbHelper;
    private Integer page;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SysUtils.setStatusBarColor(this, true, 0);
        SysUtils.setSkin(this);
        setContentView(R.layout.activity_message_edit);

        page = 0;
        tv_cacel = findViewById(R.id.tv_cacel);
        tv_finish = findViewById(R.id.tv_finish);
        et_nickname = findViewById(R.id.et_nickname);
        et_signature = findViewById(R.id.et_signature);
        tv_cacel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        dbHelper = new MyDatabaseHelper(this, "COURSE_SCHEDULE.db", null, 1);
        tv_finish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                //新增消息内容
                SQLiteDatabase db = dbHelper.getReadableDatabase();

                if (et_nickname != null && et_nickname.getText().toString().length() > 0 && et_signature != null && et_signature.getText().toString().length() > 0) {
                    String sql = "INSERT INTO \"tb_msg\"(\"msgtitle\", \"msgcontent\") VALUES ('" + et_nickname.getText().toString() + "', '" + et_signature.getText().toString() + "')";
                    db.execSQL(sql);
                    db.close();

                    finish();
                }else {
                    Toast.makeText(MessageEditActivity.this, "标题、内容不能为空！！", Toast.LENGTH_SHORT).show();
                }


            }
        });
    }

}
